package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Carinfo;
import cn.wolfcode.crm.query.CarInfoQueryObject;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.ICarInfoService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author konki
 * @time   2018年6月19日 下午7:03:47
 * @email  konki@qq.com
 * @description 
 */
@Controller
@RequestMapping("carInfo")
public class CarInfoController {
	@Autowired
   private ICarInfoService carInfoService;

	@RequestMapping("")
	@PermissionName("车辆信息列表")
	@RequiresPermissions("carInfo:index")
	public String index(){
		return "carInfo/list";
	}

    @RequestMapping("list")
	@ResponseBody
	@PermissionName("车辆信息列表")
	@RequiresPermissions("carInfo:list")
	public PageResult list(CarInfoQueryObject qo){
        return carInfoService.query(qo);
	}

	//保存
    @RequestMapping("save")
    @ResponseBody
    @PermissionName("车辆信息保存")
    @RequiresPermissions("carInfo:save")
    public JsonResult save(Carinfo entity){
        JsonResult result = new JsonResult();
        try{
            carInfoService.insert(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.markMsg("保存失败");
        }
        return  result;
    }
	//编辑
    @RequestMapping("update")
    @ResponseBody
    @PermissionName("车辆信息更新")
    @RequiresPermissions("carInfo:update")
    public JsonResult update(Carinfo entity){
        JsonResult result = new JsonResult();
        try{
            carInfoService.updateByPrimaryKey(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.markMsg("更新失败");
        }
        return  result;
    }

}
